home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Software Vault: The Games Collection 1
/
software vault.zip
/
software vault
/
CDR10
/
MAPEDIT.ZIP
/
PLOW.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-05-13
|
12KB
|
611 lines
#include "paint.h"
#include <string.h>
struct mypal_struct{
int r;
int g;
int b;
}mypal[256];
exit_prog()
{
mousecursor(0);
vmode(3);
exit(0);
}
show_screen()
{
memcpy(scrptr,bufptr,64000);
cvis=0;
}
block(int x,int y,unsigned char color)
{
int loop,loop2;
for(loop=0;loop<8;loop++)
{
for(loop2=0;loop2<8;loop2++)
{
*(scrptr+((y*8)+loop)*320+(x*8)+loop2)=color;
}
}
}
waitup()
{
while(mousebuttons())
;;
}
bigchar(char *ctp)
{
int loop,loop2;
for(loop=0;loop<8;loop++)
{
for(loop2=0;loop2<8;loop2++)
{
block(loop+1,loop2+1,*(ctp+loop+loop2*8));
}
}
}
vmode(int videomode)
{
union REGS reg;
reg.h.ah = 0;
reg.h.al = videomode;
int86 (0x10,®,®);
}
load_charset()
{
FILE *fptr;
if(!(fptr=fopen("charset.dat","rb")))
{
vmode(3);
printf("\nCould not open internal character set file charset.dat !");
exit(0);
}
fread(&csptr,1,16384,fptr);
fclose(fptr);
}
load_map(char *mapname)
{
FILE *fptr;
if(!(fptr=fopen(mapname,"rb")))
{
vmode(3);
printf("\nCould not open for reading file %s!",mapname);
exit(0);
}
fread(mapptr,sizeof(char),64000,fptr);
fclose(fptr);
}
save_map(char *mapname)
{
FILE *fptr;
if(!(fptr=fopen(mapname,"wb+")))
{
vmode(3);
printf("\nCould not open for writing file %s !",mapname);
exit(0);
}
fwrite(mapptr,sizeof(char),64000,fptr);
fclose(fptr);
}
save_attributes()
{
FILE *fptr;
if(!(fptr=fopen("chset.atr","wb+")))
{
vmode(3);
printf("\nCould not open attribute file chset.atr !");
exit(0);
}
fwrite(ca,sizeof(struct character_attribute_struct),1000,fptr);
fclose(fptr);
return;
}
load_attributes()
{
FILE *fptr;
if(!(fptr=fopen("chset.atr","rb")))
{
vmode(3);
printf("\nCould not open attribute file chset.atr !");
exit(0);
}
fread(ca,sizeof(struct character_attribute_struct),1000,fptr);
fclose(fptr);
return;
}
btc(int dx,int dy,char *dest)
{
int loop,loop2;
if(dx<0 || dx>39 || dy<0 || dy >24)
{
for(loop=0;loop<64;loop++)
{
dest[loop]=0;
}
}
else
{
for(loop=0;loop<8;loop++)
{
for(loop2=0;loop2<8;loop2++)
{
dest[loop*8+loop2]=*(bufptr+((dy*8)+loop)*320+(dx*8)+loop2);
}
}
}
}
ctb(int x, int y,char *source)
{
int loop,loop2;
for(loop=0;loop<8;loop++)
{
for(loop2=0;loop2<8;loop2++)
{
*(bufptr+((y*8)+loop)*320+(x*8)+loop2)=source[loop*8+loop2];
}
}
}
cts(int x,int y,char *source)
{
register char loop;
register char loop2;
for(loop=0;loop<8;loop++)
{
for(loop2=0;loop2<8;loop2++)
{
*(scrptr+((y*8)+loop)*320+(x*8)+loop2)=source[loop*8+loop2];
}
}
}
pch(int px,int py,unsigned int outchar)
{
register char loop;
for(loop=0;loop<8;loop++)
{
memcpy(scrptr+(py*8+loop)*320+px*8,bufptr+(((outchar/40)*8)+loop)*320+((outchar%40)*8),8);
}
}
load_db()
{
FILE * fptr;
int loop;
if(!(fptr=fopen("sprites.dat","rb")))
{
printf("\nCould not open Sprite Data file !");
exit(0);
}
fread(&db,sizeof(db),1,fptr);
fread(&si[0],sizeof(struct sprite_struct),100,fptr);
for(loop=0;loop<db.num_sprites;loop++)
{
if(!(si[loop].pict=(char far *) malloc(si[loop].width*si[loop].height)))
{
printf("\nError Allocating memory for sprite %d!",loop);
exit(0);
}
fread(si[loop].pict,si[loop].width*si[loop].height,1,fptr);
}
}
putsprite(int xs, int ys, int xlen, int ylen, char *sprbuf)
{
int loop;
for(loop=0;loop<ylen;loop++)
{
memcpy(scrptr+(ys+loop)*320+xs,sprbuf+loop*xlen,xlen);
}
}
show_sprite(int xs, int ys,char *sprname)
{
int loop;
for(loop=0;loop<db.num_sprites;loop++)
{
if(strcmpi(si[loop].name,sprname)==0)
{
mousecursor(0);
putsprite(xs,ys,si[loop].width,si[loop].height,si[loop].pict);
mousecursor(1);
return;
}
}
}
vwait()
{
while((inp(0x3da)&8))
;;
while(!(inp(0x3da)&8))
;;
}
line(int x1, int y1, int x2, int y2, int color,char xor)
{
int dx, dy, dxabs, dyabs, px, py, sdx, sdy, x, y;
int i;
dx = x2 - x1;
dy = y2 - y1;
sdx = sign(dx);
sdy = sign(dy);
dxabs = abs(dx);
dyabs = abs(dy);
x = 0;
y = 0;
px = x1;
py = y1;
if (dxabs >= dyabs)
{
for (i=0; i<dxabs; i++)
{
y += dyabs;
if (y>=dxabs)
{
y -= dxabs;
py += sdy;
}
px += sdx;
if(xor)
xplot(px,py,color);
else
plot(px,py,color);
}
}
else
{
for (i=0; i<dyabs; i++)
{
x += dxabs;
if (x>=dyabs)
{
x -= dyabs;
px += sdx;
}
py += sdy;
if(xor)
xplot(px,py,color);
else
plot(px,py,color);
}
}
}
show_chset(int scrstart,int charstart)
{
mousecursor(0);
memcpy(scrptr+scrstart*320,bufptr+charstart*8*320,320*(200-scrstart));
mousecursor(1);
}
ask_exit()
{
int mousex;
int mousey;
show_sprite(0,tbar,"quitmessage");
for(;;)
{
mousex=mousecol();
mousey=mouserow();
if(mousey>=tbar && mousey<tbar+8)
{
if(mousebuttons())
{
if(mousex>291 && mousex<307)
{
show_sprite(292,tbar,"yes");
while(mousebuttons())
;;
show_sprite(0,tbar,"mainmenubar");
ask_save();
show_sprite(0,tbar,"mainmenubar");
exit_prog();
return;
}
if(mousex>307)
{
show_sprite(308,tbar,"no");
while(mousebuttons())
;;
show_sprite(0,tbar,"mainmenubar");
return;
}
}
}
}
}
ask_save()
{
int mousex,mousey;
show_sprite(0,tbar,"savemessage");
for(;;)
{
mousex=mousecol();
mousey=mouserow();
if(mousey>=tbar && mousey<tbar+8)
{
if(mousebuttons())
{
if(mousex>291 && mousex<307)
{
show_sprite(292,tbar,"yes");
save_map(mapname);
save_pcx(charsetname,bufptr);
save_attributes();
while(mousebuttons())
;;
show_sprite(0,tbar,"mainmenubar");
return;
}
if(mousex>307)
{
show_sprite(308,tbar,"no");
while(mousebuttons())
;;
show_sprite(0,tbar,"mainmenubar");
return;
}
}
}
}
}
cross(int x, int y,int bottom,int top)
{
line(x,top,x,bottom,0xa5,1);
line(0,y,319,y,0xa5,1);
}
reverse (char *ctr)
{
char buffer[64];
int loop,loop2;
for(loop=0;loop<8;loop++)
{
memcpy(buffer,ctr+loop*8,8);
for(loop2=0;loop2<8;loop2++)
{
*(ctr+loop*8+7-loop2)=*(buffer+loop2);
}
}
}
up (char *ctr)
{
char temp[64];
int loop,loop2;
memcpy(temp,ctr,8);
for(loop=0;loop<7;loop++)
{
memcpy(ctr+loop*8,ctr+(loop+1)*8,8);
}
memcpy(ctr+7*8,temp,8);
}
down(char *ctr)
{
char temp[64];
int loop,loop2;
memcpy(temp,ctr+7*8,8);
for(loop=7;loop>0;loop--)
{
memcpy(ctr+(loop)*8,ctr+(loop-1)*8,8);
}
memcpy(ctr,temp,8);
}
left(char *ctr)
{
char temp;
int loop,loop2;
for(loop=0;loop<8;loop++)
{
temp=*(ctr+loop*8);
for(loop2=0;loop2<7;loop2++)
*(ctr+loop*8+loop2)=*(ctr+loop*8+loop2+1);
*(ctr+loop*8+7)=temp;
}
}
right(char *ctr)
{
char temp;
int loop,loop2;
for(loop=0;loop<8;loop++)
{
temp=*(ctr+loop*8+7);
for(loop2=7;loop2>0;loop2--)
*(ctr+loop*8+loop2)=*(ctr+loop*8+loop2-1);
*(ctr+loop*8)=temp;
}
}
set_palette()
{
register int loop;
for(loop=0;loop<256;loop++)
{
outp(0x3c8,loop);
outp(0x3c9,pal[loop].red);
outp(0x3c9,pal[loop].green);
outp(0x3c9,pal[loop].blue);
mypal[loop].r=pal[loop].red;
mypal[loop].g=pal[loop].green;
mypal[loop].b=pal[loop].blue;
}
}
makepal()
{
int loop,loop2,loop3;
union REGS inregs,outregs;
int count;
pal[0].red=0;
pal[0].green=0;
pal[0].blue=0;
pal[1].red=255;
pal[1].green=255;
pal[1].blue=255;
count=2;
for(loop=0;loop<32;loop++)
{
pal[count].red=loop*2;
pal[count].green=loop*2;
pal[count].blue=loop*2;
count++;
}
for(loop=0;loop<6;loop++)
{
for(loop2=0;loop2<6;loop2++)
{
for(loop3=0;loop3<6;loop3++)
{
pal[count].red=(loop*10); /* red */
pal[count].green=(loop2*10); /* green */
pal[count].blue=(loop3*10); /* blue */
count++;
}
}
}
}
show_pal()
{
int loop,loop2;
block(0,18,0);
block(1,18,1);
for(loop=0;loop<32;loop++)
{
block(loop+2,18,loop+2);
}
for(loop=0;loop<36;loop++)
{
for(loop2=0;loop2<6;loop2++)
{
block(loop,loop2+19,loop*6+loop2+34);
}
}
}
int what_color(int x,int y)
{
if(x<288)
{
if(y<152 && y >143)
{
if(x>271)
return(-1);
else
return(x/8);
}
if(y>151)
return(x/8*6+y/8-19+34);
}
return(-1);
}
mapline(int mapx,int mapy,int x1, int y1, int x2, int y2, int linechar)
{
int dx, dy, dxabs, dyabs, px, py, sdx, sdy, x, y;
int i;
memset(screen,0xff,2000);
dx = x2 - x1;
dy = y2 - y1;
sdx = sign(dx);
sdy = sign(dy);
dxabs = abs(dx);
dyabs = abs(dy);
x = 0;
y = 0;
px = x1;
py = y1;
if (dxabs >= dyabs)
{
for (i=0; i<dxabs; i++)
{
y += dyabs;
if (y>=dxabs)
{
y -= dxabs;
py += sdy;
}
px += sdx;
mapptr[mapx+px+(mapy+py)*320]=linechar;
pch(px,py,linechar);
}
}
else
{
for (i=0; i<dyabs; i++)
{
x += dxabs;
if (x>=dyabs)
{
x -= dyabs;
px += sdx;
}
py += sdy;
mapptr[mapx+px+(mapy+py)*320]=linechar;
pch(px,py,linechar);
}
}
}
putsline(int x,char *string)
{
int loop,loop2;
for(loop=0;loop<strlen(string);loop++)
for(loop2=0;loop2<8;loop2++)
memcpy(scrptr+(loop+x)*8+(loop2)*320,csptr[*(string+loop)][loop2],8);
}